function renderTemplate(tmpl,data){
	
	var context = Template7.compile($$("#"+tmpl).html())
	var html = context(data);
	
	$("#"+tmpl).next("div[data-template='"+ tmpl +"']").remove();
	$("#"+tmpl).after("<div data-template='"+ tmpl +"'>" + html + "</div>");
	
}

// Initialize your app
var app = new Framework7({
	animatePages: false,
	pushState : true,
	pushStateSeparator : '#!/',
	modalTitle : "XX商城",
	modalButtonOk : "确定",
	modalButtonCancel : "取消",
});

// Export selectors engine
var $$ = Dom7;

// Add view
var mainView = app.addView('.view-main', {
	//dynamicNavbar: true // Because we use fixed-through navbar we can enable dynamic navbar
});


app.onPageInit('category', function (page) {
	$$(".category-menu a").on('click', function (e) {
		$$(".category-menu a").removeClass("selected");
		$$(this).addClass("selected");
		$$.get("/api/tmmenu/"+$$(this).attr("data-cid"), {}, function(data){
			renderTemplate("tmpl-category-list", data)
		});
	});
});
app.onPageInit('home', function (page) {
	var advSwiper = app.swiper('#advert-swiper', {
		pagination:'.swiper-pagination',
		spaceBetween: 16
	});
	var recmdSwiper = app.swiper('#recmd-swiper', {
		spaceBetween: 10,
		slidesPerView: 3
	});
	var searchbar = app.searchbar('.searchbar', {
		/*searchList: '.list-block-search',
		searchIn: '.item-title'*/
	});
});

$$(".toolbar .tab-link").on('click', function (e) {
	$$(".toolbar .tab-link").removeClass("active");
	$$(this).addClass("active");
	var url = $$(this).attr('data-url');
	mainView.router.loadPage(url);
});

mainView.router.loadPage('home');
